#include<iostream>
using namespace std;

int s[1000], t[1000], dp[1001];

int main()
{
    int n, v;
    cin >> n >> v;
    for(int i = 0; i < n; i++) cin >> s[i] >> t[i];
    for (int i = 0; i < n; i++)
        for (int j = v; j >= s[i]; j--)
            dp[j] = max(dp[j], dp[j - s[i]] + t[i]);
    cout << dp[v];

    return 0;
}
